<?php
namespace Home\Controller;
use Think\Controller;
class CommonController extends Controller {
    /*
    *自动执行的方法
    */
	public function _initialize()
	{
        //组合访问的路径
		$path = CONTROLLER_NAME.'/'.ACTION_NAME;

        //判断是否需要进行权限验证
		if(in_array($path, C('AUTH_PATH'))){
			//判断是否登录
			if(!isset($_SESSION['nikename'])){
                //没登录跳转
    		    $this->error('你还没有登录，请先登录',U('home/Enter/index'));
    		}
		}
		
	}
    //检测人类验证是否通过
    public function checkVercode()
    {
    	$vercode = I('post.vercode');

        if($vercode!=$_SESSION['vercode_answer']){
            $arr = array(
            'error'=>'1',
            'info'=>'人类验证不通过'
            );
            echo json_encode($arr);
            exit;
        }
    }
    //给问题状态分类
    public function staTree($class,$fid=0)
    {   
        $temp=array();
        foreach ($class as $v ){
            if ($v['fid']==$fid) {
                $v['son']=$this->staTree($class, $v['id']);
                $temp[]=$v;
            }
        }
        return $temp;
    }
    // 自增加
    public function inc($table,$filed,$id,$num)
    {

        // $datda[$filed]= $filed+$num;
        // M($table)->where("id='$id'")->save($data);
        $sql ="Update ".$table." set ".$filed."=".$filed."+".$num." where id=".$id;

        M()->execute($sql);
    }
}
?>